package com.mew.lobby.handler.events.days;

import com.mew.common.exception.ResponseCode;
import com.mew.common.rest.IntMessage;
import com.mew.common.rest.bo.MewSession;
import com.mew.common.rest.events.GetOnlineGiftMessage;
import com.mew.common.rest.user.UserMoneyResponseMessage;
import com.mew.lobby.annotation.LobbyHandler;
import com.mew.lobby.net.LobbyHandlerMapCmdType;
import com.mew.lobby.net.MewHandler;
import com.mew.lobby.provide.EventsFeignService;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@LobbyHandler(LobbyHandlerMapCmdType.OnlineGiftGet)
public class OnlineGiftGetHandler implements MewHandler<IntMessage> {

    @Autowired
    private EventsFeignService eventsFeignService;

    @Override
    public void handle(ZebraCommand<IntMessage> zebraCommand, MewSession session) {
        log.info("{}",zebraCommand.getRequest());
        int i = zebraCommand.getRequest().getI();
        long userId = zebraCommand.getUserId();
        GetOnlineGiftMessage message = eventsFeignService.get(i, userId);

        if (message.getStatus()== ResponseCode.Success.code()){
            zebraCommand.sendMessage(message);
            return;
        }

        zebraCommand.sendFailureCode(message.getStatus());
    }
}
